package org.example.java.util.concurrency;

import java.util.concurrent.TimeUnit;

/**
 * User: ZhangJuntao
 * Date: 13-9-3
 * Time: 上午7:28
 */
public class ThreadAddTest {
  static class Count {
    private int num = 0;

    public synchronized void count() {
      for (int i = 1; i <= 4; i++) {
        num += i;
        try {
          TimeUnit.MILLISECONDS.sleep(10);
        } catch (InterruptedException e) {
          e.printStackTrace();
        }
      }
      System.out.println(Thread.currentThread().getName() + "-" + num);
    }
  }

  public static void main(String[] args) {
    final Count count = new Count();
    for (int i = 0; i < 10; i++) {
//      new Thread(new Runnable() {
//        public void run() {
//          count.count();
//        }
//      }).start();
      new Thread() {
        public void run() {
          count.count();
        }
      }.start();
    }
  }
}
